package likou;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/24 08:28
 */
public class _30 {
    public static void main(String[] args) {
        System.out.println(findSubstring("wordgoodgoodgoodbestword",
                new String[]{"word","good","best","good"}));
    }
    static List<Integer> res = new ArrayList<>();
    public static List<Integer> findSubstring(String s, String[] words) {
        int len = 0;
        for (String str : words) {
            len += str.length();
        }
        for (int i = 0; i <= s.length() - len; i++) {
            if (findSub(s.substring(i, i + len), words)){
                res.add(i);
            }
        }
        return res;
    }

    public static boolean findSub(String s, String[] words) {
        int index = 0;
        boolean[] yes = new boolean[words.length];
        int y = 0;
        for (int i = 0; i < words.length; i++) {
            if (!yes[i] && s.startsWith(words[i], index)) {
                yes[i] = true;
                index += words[i].length();
                i = -1;
                y++;
            }
        }
        return y == words.length;
    }
}
